package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.CremationTimeSegmentEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 火化预约时间段表Provider
 *
 * @author generator
 * @date 2020-03-12 17:08
 */
public class CremationTimeSegmentProvider {

    /**
     * 增加CremationTimeSegment
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String insertCremationTimeSegment(@Param("entity") CremationTimeSegmentEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" cremation_time_segment ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" furnace_type_code ", " #{entity.furnaceTypeCode,jdbcType=SMALLINT} ");
                VALUES(" appointment_time_segment ", " #{entity.appointmentTimeSegment,jdbcType=VARCHAR} ");
                VALUES(" sort ", " #{entity.sort,jdbcType=INTEGER} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改CremationTimeSegment
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String updateCremationTimeSegment(@Param("entity") CremationTimeSegmentEntity entity) {
        return new SQL() {
            {
                UPDATE(" cremation_time_segment ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" furnace_type_code = #{entity.furnaceTypeCode,jdbcType=SMALLINT} ");
                SET(" appointment_time_segment = #{entity.appointmentTimeSegment,jdbcType=VARCHAR} ");
                SET(" sort = #{entity.sort,jdbcType=INTEGER} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询CremationTimeSegment列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String listCremationTimeSegment(@Param("entity") CremationTimeSegmentEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,furnace_type_code,appointment_time_segment,sort,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" cremation_time_segment ");

                if (entity.getFurnaceTypeCode() != null) {
                    WHERE(" furnace_type_code = #{entity.furnaceTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getAppointmentTimeSegment() != null) {
                    WHERE(" appointment_time_segment = #{entity.appointmentTimeSegment,jdbcType=VARCHAR} ");
                }

                if (entity.getSort() != null) {
                    WHERE(" sort = #{entity.sort,jdbcType=INTEGER} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}